<?php

use yii\db\Migration;

/**
 * Class m200619_101629_user
 */
class m200619_101629_user extends Migration
{
    /**
     * {@inheritdoc}
     */


    // Use up()/down() to run migration code without a transaction.
    public function up()
    {
        $tableOptions = null;
        if ($this->db->driverName === 'mysql') {
            // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
            $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
        }

        $this->createTable('{{%user}}', [
            'id'               => $this->integer(),
            'username'         => $this->string()->notNull()->defaultValue(''),
            'auth_key'         => $this->string(32)->notNull()->defaultValue(''),
            'password_hash'    => $this->string(255)->notNull()->defaultValue(''),
            'password_reset_token' => $this->string(255),
            'mobile'           => $this->string(11)->notNull()->defaultValue(''),
            'gender'           => $this->tinyInteger()->defaultValue(0),
            'email'            => $this->string(32)->notNull()->defaultValue(''),
            'head_thumb'       => $this->string(255)->notNull()->defaultValue(''),
            'status'           => $this->tinyInteger()->notNull()->defaultValue(1),
            'created_at'       => $this->integer()->notNull(),
            'updated_at'       => $this->integer()->notNull(),
            'verification_token'=> $this->string(255),
            'PRIMARY KEY ([[id]])',
        ], $tableOptions);

        $this->createTable('{{%user_token}}', [
            'token'              => $this->string()->notNull()->defaultValue(''),
            'user_id'            => $this->integer()->notNull()->defaultValue(''),
            'app_id'             => $this->string()->notNull()->defaultValue(''),
            'expires_in'         => $this->integer()->notNull(),
            'forced_offline'     => $this->tinyInteger(1)->defaultValue(0)->notNull(),
            'refresh_expires_in' => $this->integer()->notNull(),
            'refresh_token'      => $this->string()->notNull()->defaultValue(''),
            'data'               => $this->text(),
        ], $tableOptions);
    }

    public function down()
    {
        $this->dropTable('{{%user}}');
        $this->dropTable('{{%user_token}}');
        return false;
    }


    /* public function safeUp()
     {

     }

     public function safeDown()
     {
         echo "m200619_101629_user cannot be reverted.\n";

         return false;
     }*/

}
